package com.kkb.kkbcommon.basic;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: zml
 * @Description:
 * @Data Created in 2021-08-05 20:28
 * @Modified by:
 */
public class BaseUtil {
    /**
     * @Author: zml
     * @Description: 判断参数列表全不为null
     * @Data Created in 2021-06-11 18:20:31
     * @Modified by:
     *
     * @param objects 参数列表
     */
    public static boolean isNotNull(Object...objects){
        boolean flag = true;
        for (Object object : objects) {
            flag = object != null;
            if (!flag) {
                break;
            }
        }
        return flag;
    }

    /**
     * @Author: zml
     * @Description: 判断参数列表全不为空
     * @Data Created in 2021-07-12 14:36:43
     * @Modified by:
     *
     * @param objects 参数列表
     */
    public static boolean isNotEmpty(Object...objects){
        if (haveNull(objects)){
            return false;
        }

        boolean flag = true;

        for (Object object: objects){
            if (object instanceof String){
                flag = !"".equals(((String) object).trim());
            }else if (object instanceof Map){
                flag = !((Map<?, ?>) object).isEmpty();
            }else if (object instanceof List){
                flag = !((List<?>) object).isEmpty();
            }else if (object instanceof File){
                flag = ((File) object).exists();
            }
            if (!flag) {
                break;
            }
        }
        return flag;
    }

    /**
     * @Author: zml
     * @Description: 判断参数列表存在空
     * @Data Created in 2021-07-12 14:36:43
     * @Modified by:
     */
    public static boolean haveEmpty(Object...objects){
        return !isNotEmpty(objects);
    }

    /**
     * @Author: zml
     * @Description: 判断参数是否存在null
     * @Data Created in 2021-08-05 20:32:40
     * @Modified by:
     *
     * @param objects 参数列表
     */
    public static boolean haveNull(Object...objects){
        return !isNotNull(objects);
    }

    /**
     * @Author: zml
     * @Description: 将数组转换成可变列表
     * @Data Created in 2021-07-12 14:22:39
     * @Modified by:
     *
     * @param <T> 泛型
     * @param arr 数组
     */
    public static <T> List<T> convertArrayToList(T[] arr){
        return new ArrayList<>(Arrays.asList(arr));
    }
}
